package developer.zyk.global.config;

import developer.zyk.global.common.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Log4j2
public class GlobalExceptionHandler {


    @ExceptionHandler(Exception.class)
    public ResponseEntity<Result<String>> handlerException(Exception e) {
        ResponseEntity<Result<String>> resultResponseEntity = new ResponseEntity<Result<String>>(Result.fail(500, e.getMessage()), HttpStatus.OK);
        log.error("系统异常:{}", e.getMessage(), e);
        return resultResponseEntity;
    }
}
